package isjinhao.jlox.grammar.code.visitor;

import isjinhao.jlox.grammar.code.represention.Block;
import isjinhao.jlox.grammar.code.represention.Code;
import isjinhao.jlox.grammar.statement.represention.Statement;
import isjinhao.jlox.run.Environment;

import java.util.Iterator;
import java.util.List;

/**
 * @Author ISJINHAO
 * @Date 2021/3/1 11:08
 */
public class CodeEvaluator implements CodeVisitor<Void>{

    @Override
    public Void visitBlockStmt(Block block) {
        Environment previous = environment;
        environment = new Environment(previous);

        List<Statement> statements = block.getStatements();
        Iterator<Statement> iterator = statements.iterator();
        while(iterator.hasNext()) {
            Statement statement = iterator.next();
            statement.accept(this);
        }
        environment = previous;
        return null;
    }
}
